Plugin Interface ================================= Plugin API ---------- - Plugin initialisation .. c:function:: extern "C" int UserHook_init(const char *vers) Initialises the plugin. :param vers: current version of calling Fred executable :type vers: const char * :return: error code (0=OK) :rtype: int - Plugin final call .. c:function:: extern "C" int UserHook_close() The plugin can do postprocessing, bookkeeping, writing a summary report, etc. before the simulation is ended. :return: error code (0=OK) :rtype: int - Step-by-step control of particle tracking These functions allow the user to monitor and/or alter the propagation of a given particle at the level of a single step. They are called just before and just after the internal routines that advance the particle by a step. .. c:function:: extern "C" int UserHook_step_bfr(Step *stp) Control is given to the plugin **before** taking the step. :param stp: current step structure :type stp: Step * :return: APPLY/SKIP :rtype: int If APPLY is returned, Fred internal *step routines* will executed, hence the plugin acts as a diagnostic tool, not changing the particle evolution. If instead `SKIP` is returned, then internal step routines are bypassed, and the plugin is taking complete control of the stepping procedure. .. c:function:: extern "C" void UserHook_step_aft(Step *stp) Control is given to the plugin **after** taking the step. The plugin can monitor the stepping procedure and score quantities at the step level. :param stp: current step structure :type stp: Step * :return: none - Plugin runtime and execution options .. c:function:: extern "C" bool isPluginThreadSafe() Tell Fred that the plugin can be executed in parallel on many threads. It is reponsability of the developer to check that data race conditions are not occurring during multi-thread execution. By default, Fred assumes that plugin code is **not thread-safe** and switches to serial, i.e. single-thread, execution. Semaphore control functions are provided for enforcing atomic operations on shared data. :return: true if plugin is thread-safe :rtype: bool - Boundary crossing .. c:function:: extern "C" void UserHook_domain_boundary_crossing(Step * stp,bool entering) ... :param stp: current step structure :type stp: Step * :param bool entering: :return: none Getting input parameters for the plugin --------------------------------------- Input parameters for the plugin can be written in the main input file (e.g. ``fred.inp``) and queried using plugin parsing routines. .. important:: User-defined parameters must be enclosed in a multiline **plugin<...plugin>** directive as in the following example: .. code-block:: :emphasize-lines: 1,7 plugin< myInt = 374 myBool = false myString = 'profile.dat' myFloat = -1.234e-12 myVec = [1,4,3] plugin> .. c:function:: bool getBoolParam(const char *pname,bool defVal) :param pname: parameter name :type pname: const char * :param bool defVal: default value returned if parameter not found in the input file :return: the value of the specified parameter :rtype: bool :: bool verbose = getBoolParam("lPluginVerbose",false); if (verbose) cout<<"Plugin verbose mode is switched on."< of the material :rtype: float32 .. c:function:: float32 getMat_Amean(int imat) :param imat: material index :type stp: int32 :return: average mass number (g/mol) of the material :rtype: float32 .. c:function:: float32 getMat_RelStopPow(int imat) :param imat: material index :type stp: int32 :return: relative stopping power of the material :rtype: float32 .. c:function:: float32 getMat_Lrad(int imat) :param imat: material index :type stp: int32 :return: radiation length (g/cm^2) of the material :rtype: float32 .. c:function:: int16 getHU(int imat) :param imat: material index :type stp: int32 :param int32 iel: index of element in the material :return: HU value of the material (if not defined, returns -10000) :rtype: int16 Elemental composition --------------------- Query functions for elemental composition: .. c:function:: int32 getMatNumElements(int imat) :param imat: material index :type stp: int32 :return: number of elements in the material :rtype: int32 single elements in the material are indexed from 0 .. c:function:: float32 getMat_Z(int imat, int32 iel) :param imat: material index :type stp: int32 :param int32 iel: index of element in the material :return: num of protons in element nucleus (P) :rtype: float32 .. c:function:: float32 getMat_A(int imat, int32 iel) :param imat: material index :type stp: int32 :param int32 iel: index of element in the material :return: num of nucleons in element nucleus (N+P) :rtype: float32 .. c:function:: float32 getMat_m(int imat, int32 iel) :param imat: material index :type stp: int32 :param int32 iel: index of element in the material :return: mass of element nucleus (MeV/c^2) :rtype: float32 .. c:function:: float32 getMat_w(int imat, int32 iel) :param imat: material index :type stp: int32 :param int32 iel: index of element in the material :return: weight fraction of element in the material :rtype: float32 .. c:function:: float32 getMat_x(int imat, int32 iel) :param imat: material index :type stp: int32 :param int32 iel: index of element in the material :return: number fraction of element in the material :rtype: float32 Example: :: int imat = getImat_A(stp); int nel = getMatNumElements(imat); cout<